package com.hospital.yygh.common.utils;

import com.hospital.yygh.common.helper.JwtHelper;

import javax.servlet.http.HttpServletRequest;

/**
 * 获取当前用户信息的工具类
 */
public class AuthContextHolder {

    /**
     * 获取当前用户id
     * @param request
     * @return
     */
    public static Long getUserId(HttpServletRequest request){
        // 从header中获取token
        String token = request.getHeader("token");
        // 从token中获取userId
        Long userId = JwtHelper.getUserId(token);
        return userId;
    }

    /**
     * 获取当前用户名称
     * @param request
     * @return
     */
    public static Long getUserName(HttpServletRequest request){
        // 从header中获取token
        String token = request.getHeader("token");
        // 从token中获取userName
        Long userName = JwtHelper.getUserId(token);
        return userName;
    }

}
